<?php
namespace EasyVote\EasyVoteBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\Persistence\ObjectManager;
use EasyVote\EasyVoteBundle\Entity\Department;
use EasyVote\EasyVoteBundle\Entity\User;
use EasyVote\EasyVoteBundle\Entity\Profile;
use EasyVote\EasyVoteBundle\Entity\Email;

/**
 * Class LoadUserData
 * Loads user data into the database
 * @package EasyVote\EasyVoteBundle\DataFixtures\ORM
 */
class LoadUserData extends AbstractFixture implements OrderedFixtureInterface
{
    /**
     * {@inheritDoc}
     */
    public function load(ObjectManager $manager)
    {
        $roleRepo = $manager->getRepository('EasyVoteBundle:Role');
        $adminRole = $roleRepo->findOneByValue('ROLE_ADMIN');

        $adminUser = new User();
        $adminUser->setEuid('xyz1234');
        $adminUser->setPrincipalName('xyz1234@unt.edu');
        $adminUser->setEmployeeNumber('12345678');
        $adminUser->addRole($adminRole);
        $manager->persist($adminUser);
        $manager->flush();

        //make default profile
        $profile = $adminUser->getProfile();
        if ($profile == null) {
            $profile = new Profile();
            $profile->setPicture("http://placehold.it/200x200");
            $profile->setSummary("Default Summary");
            $profile->setText("Default Text");
            $profile->setTitle("Default Title");
            $manager->persist($profile);
            $manager->persist($adminUser);
            $manager->flush();
        }


    }

    /**
     * {@inheritDoc}
     */
    public function getOrder()
    {
        return 8; // the order in which fixtures will be loaded
    }
}

?>
